// 通用JSON原子类型定义，避免使用 any/unknown
export type AnyJson = string | number | boolean | null | { [key: string]: AnyJson } | AnyJson[]

export interface ApiResponse<T> {
  code: number
  msg: string
  data: T
}

export interface PaginationParams {
  page?: number
  size?: number
}

export interface PaginationResult<T> {
  total: number
  page: number
  size: number
  pages: number
  list: T[]
}

// 与后端 PageResult 对齐的类型别名
export type PageResult<T> = PaginationResult<T>

export interface SearchQuery extends PaginationParams {
  keyword?: string
}

export type FilterQuery = PaginationParams &
  Record<string, string | number | boolean | null | undefined>

export interface ApiError {
  code: number
  message: string
  details?: AnyJson
}

export interface UploadResponse {
  url: string
  filename: string
  size: number
  mimeType: string
}

// 成功响应结构（兼容部分后端 { success, data, message } 返回）
export interface SuccessResponse<T> {
  success: boolean
  message?: string
  data: T
}

// PageHelper 的简化分页结构（与后端 PageInfo 关键字段对齐）
export interface PageInfo<T> {
  list: T[]
  total: number
  pageNum?: number
  pageSize?: number
  pages?: number
}
